package com.yeyaomai.dksns.flowis.service.result;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.Set;

import com.yeyaomai.dksns.flowis.domain.Browser;
import com.yeyaomai.dksns.flowis.domain.Module;
import com.yeyaomai.dksns.flowis.domain.Operator;
import com.yeyaomai.dksns.flowis.domain.ReferCategory;
import com.yeyaomai.dksns.flowis.domain.ReferDomain;
import com.yeyaomai.dksns.flowis.domain.ReferPage;
import com.yeyaomai.dksns.flowis.domain.TrendAnalysisDay;
import com.yeyaomai.dksns.flowis.domain.TrendAnalysisHour;
import com.yeyaomai.dksns.flowis.domain.VisitArea;
import com.yeyaomai.dksns.flowis.domain.flowisdetail.FlowisStatDetailDTO;
import com.yeyaomai.dksns.flowis.util.Globals;
import com.yeyaomai.dksns.flowis.util.StringUtil;
import com.yeyaomai.dksns.flowis.util.VelocityToolDateUtils;

/**
 * 生成动态XMl类
 * 
 * @author xiaqin
 * 
 */
public class DynamicXml {

	/**
	 * 拼装柱状图
	 * 
	 * @param value
	 * @return
	 */
	public static String getColumn(String value) {
		String[] values = value.split("\\|");
		String[] trendnu = values[0].split(",");

		long[] trendnumber = new long[24];
		int n;
		for (n = 0; n < trendnu.length; n++) {
			trendnumber[n] = Long.valueOf(trendnu[n]);
		}

		long min = trendnumber[0];
		long max = trendnumber[0];
		int maxtime = 0;
		int mintime = 0;
		int m;
		for (m = 0; m < trendnumber.length; m++) {
			if (max < trendnumber[m]) {
				max = trendnumber[m];
				maxtime = m;
			}
			if (min > trendnumber[m] && trendnumber[m] >= 0) {
				min = trendnumber[m];
				mintime = m;
			}
		}
		String type = values[1];
		if (type.equals("UV")) {
			type = "独立访客";
		}
		if (type.equals("NUV")) {
			type = "新独立访客";
		}

		String xml = "";
		xml = "<chart showFCMenuItem='0' palette='2'caption='最大值 ["
				+ maxtime
				+ ":00]  "
				+ max
				+ "   最小值["
				+ mintime
				+ ":00]  "
				+ min
				+ " ' canvasBorderAlpha='20'"
				+ "bgColor='FFFFFF' unescapeLinks='0' limitsDecimalPrecision='1' canvasBorderThickness='1' showBorder='0'"
				+ "legendBorderAlpha='0' bgAngle='360' showlegend='1' showValues='1'"
				+ "decimals='2' useRoundEdges='0' baseFontSize='9' outCnvbaseFontSize='10'"
				+ "use3DLighting='0' numberScaleValue='10000,1,1,1000' formatNumberScale='1'"
				+ "numberScaleUnit=' , ,万,千万 ' toolTipSepChar='：  ' plotFillRatio=''"
				+ "chartRightMargin='6' chartTopMargin='0' chartLeftMargin='0'"
				+ "chartBottomMargin='3' showShadow='0' labelStep='2' animation='0'>";
		int a;
		for (a = 0; a < 24; a++) {
			xml += "<set label='" + a + ":00' value='" + trendnumber[a]
					+ "' toolText='" + type + ": " + trendnumber[a] + "' />";
		}

		xml += "<styles><definition><style name='CaptionFont' type='font' size='12' /></definition>"
				+ "<application><apply toObject='caption' styles='CaptionFont' /></application></styles></chart>";
		return xml;
	}

	/**
	 * 
	 * @param trendAnalysisDayList
	 * @param end
	 * @param keys
	 *            分别是pv,ip,uv,newuser
	 * @return
	 */
	// 最近30天月统计
	public static String getLine30(List<TrendAnalysisDay> trendAnalysisDayList,
			String end, String keys, int fetchDays) {

		String pv = "<dataset  seriesName='PV' color='0033CC' anchorBorderColor='0033CC'  >";
		String ip = "<dataset  seriesName='IP' color='FF0000' anchorBorderColor='FF0000'  >";
		String uv = "<dataset  seriesName='独立访客' color='33CC33' anchorBorderColor='33CC33'  >";
		String nuv = "<dataset  seriesName='新独立访客' color='#ffa902' anchorBorderColor='#ffa902'  >";
		String tail = "<styles><definition><style name='CaptionFont' type='font' size='12'  /><style name='myLegendFont' type='font' size='11'  /></definition><application><apply toObject='CAPTION' styles='CaptionFont'  /><apply toObject='SUBCAPTION' styles='CaptionFont'  /><apply toObject='Legend' styles='myLegendFont'  /></application></styles></chart>";

		StringBuffer xml = new StringBuffer();
		xml.append("<chart showFCMenuItem='0' lineThickness='2' showValues='0' anchorRadius='4' divLineAlpha='20' divLineColor='CC3300' divLineIsDashed='1' showAlternateHGridColor='1' alternateHGridAlpha='5' alternateHGridColor='CC3300' shadowAlpha='40' labelStep='5' numvdivlines='28' showAlternateVGridColor='1' chartsshowShadow='1' chartRightMargin='35' chartTopMargin='15' chartLeftMargin='10' chartBottomMargin='3' bgColor='FFFFFF' canvasBorderThickness='1' showBorder='0' legendBorderAlpha='0' bgAngle='360' showlegend='0' borderColor='DEF3F3' toolTipBorderColor='cccc99' canvasPadding='0' toolTipBgColor='ffffcc' legendShadow='0' baseFontSize='12' canvasBorderAlpha='20' outCnvbaseFontSize='10' outCnvbaseFontColor='000000' numberScaleValue='10000,1,1,1000' formatNumberScale='1' palette='2' numberScaleUnit=' , ,万,千万' lineColor='AFD8F8'  ><categories  >");
		String[] dateRetStr = VelocityToolDateUtils.getSpecifiedContinusDays(
				null, end, fetchDays, null, Globals.CONDITION_A).split(",");
		String[] dateRetStrb = VelocityToolDateUtils.getSpecifiedContinusDays(
				null, end, fetchDays, Globals.DATE_FORMAT_B,
				Globals.CONDITION_A).split(",");
		for (int i = 0; i < dateRetStr.length; i++) {

			xml.append("<category label='");
			xml.append(dateRetStr[i]);
			xml.append("'  />");

		}
		xml.append("</categories>");

		Map<String, String> dateMap = Collections
				.synchronizedMap(new TreeMap<String, String>());
		Map<String, TrendAnalysisDay> objectMap = new HashMap<String, TrendAnalysisDay>();

		for (TrendAnalysisDay day : trendAnalysisDayList) {
			objectMap.put(Globals.FORMAT_TYPE_B.format(day.getTrendDay()), day);
		}

		// if exists
		if (keys.indexOf("pv") != -1) {
			xml.append(pv);
			// 拼成原始串
			for (int i = 0; i < dateRetStrb.length; i++) {
				dateMap.put(dateRetStrb[i], "<set  value='0' toolText='PV: 0 "
						+ dateRetStr[i] + "'  />");
			}

			for (Entry<String, String> entry : dateMap.entrySet()) {
				String key = entry.getKey();
				if (objectMap.containsKey(key)) {
					String dataValue = entry.getValue();
					TrendAnalysisDay day = objectMap.get(key);
					String newValue = dataValue.replace(
							"value='0' toolText='PV: 0",
							"value='" + day.getPageView() + "'toolText='PV: "
									+ day.getPageView());
					// 渲染
					dateMap.put(key, newValue);
				}
			}
			xml.append(handleMap(dateMap));
			// clear
			dateMap.clear();
			xml.append("</dataset>");
		}
		if (keys.indexOf("ip") != -1) {
			xml.append(ip);

			for (int i = 0; i < dateRetStrb.length; i++) {
				dateMap.put(dateRetStrb[i], "<set  value='0' toolText='IP: 0 "
						+ dateRetStr[i] + "'  />");
			}

			for (Entry<String, String> entry : dateMap.entrySet()) {
				String key = entry.getKey();
				if (objectMap.containsKey(key)) {
					String dataValue = entry.getValue();
					TrendAnalysisDay day = objectMap.get(key);
					String newValue = dataValue.replace(
							"value='0' toolText='IP: 0",
							"value='" + day.getIp() + "'toolText='IP: "
									+ day.getIp());
					// 渲染
					dateMap.put(key, newValue);
				}
			}
			xml.append(handleMap(dateMap));
			dateMap.clear();

			xml.append("</dataset>");

		}
		if (keys.indexOf("uv") != -1) {

			xml.append(uv);
			for (int i = 0; i < dateRetStrb.length; i++) {
				dateMap.put(dateRetStrb[i],
						"<set  value='0' toolText='独立访客: 0 " + dateRetStr[i]
								+ "'  />");
			}
			for (Entry<String, String> entry : dateMap.entrySet()) {
				String key = entry.getKey();
				if (objectMap.containsKey(key)) {
					String dataValue = entry.getValue();
					TrendAnalysisDay day = objectMap.get(key);
					String newValue = dataValue
							.replace("value='0' toolText='独立访客: 0", "value='"
									+ day.getUniqueHost() + "'toolText='独立访客: "
									+ day.getUniqueHost());
					// 渲染
					dateMap.put(key, newValue);
				}
			}
			xml.append(handleMap(dateMap));
			dateMap.clear();
			xml.append("</dataset>");
		}
		if (keys.indexOf("newuser") != -1) {
			xml.append(nuv);
			for (int i = 0; i < dateRetStrb.length; i++) {
				dateMap.put(dateRetStrb[i],
						"<set  value='0' toolText='新独立访客: 0 " + dateRetStr[i]
								+ "'  />");
			}
			for (Entry<String, String> entry : dateMap.entrySet()) {
				String key = entry.getKey();
				if (objectMap.containsKey(key)) {
					String dataValue = entry.getValue();
					TrendAnalysisDay day = objectMap.get(key);
					String newValue = dataValue.replace(
							"value='0' toolText='新独立访客: 0",
							"value='" + day.getNewUniqueHost()
									+ "'toolText='新独立访客: "
									+ day.getNewUniqueHost());
					// 渲染
					dateMap.put(key, newValue);
				}
			}
			xml.append(handleMap(dateMap));
			dateMap.clear();
			xml.append("</dataset>");
		}
		xml.append(tail);
		// System.out.println(xml.toString());
		return xml.toString();
	}

	// 本月统计拼串
	public static String getLinetoMonth(
			List<TrendAnalysisDay> trendAnalysisDayList, String start,
			String end, String keys) {

		String pv = "<dataset  seriesName='PV' color='0033CC' anchorBorderColor='0033CC'  >";
		String ip = "<dataset  seriesName='IP' color='FF0000' anchorBorderColor='FF0000'  >";
		String uv = "<dataset  seriesName='独立访客' color='33CC33' anchorBorderColor='33CC33'  >";
		String nuv = "<dataset  seriesName='新独立访客' color='#ffa902' anchorBorderColor='#ffa902'  >";
		String tail = "<styles><definition><style name='CaptionFont' type='font' size='12'  /><style name='myLegendFont' type='font' size='11'  /></definition><application><apply toObject='CAPTION' styles='CaptionFont'  /><apply toObject='SUBCAPTION' styles='CaptionFont'  /><apply toObject='Legend' styles='myLegendFont'  /></application></styles></chart>";

		StringBuffer xml = new StringBuffer();
		xml.append("<chart showFCMenuItem='0' lineThickness='2' showValues='0' anchorRadius='4' divLineAlpha='20' divLineColor='CC3300' divLineIsDashed='1' showAlternateHGridColor='1' alternateHGridAlpha='5' alternateHGridColor='CC3300' shadowAlpha='40' labelStep='5' numvdivlines='28' showAlternateVGridColor='1' chartsshowShadow='1' chartRightMargin='35' chartTopMargin='15' chartLeftMargin='10' chartBottomMargin='3' bgColor='FFFFFF' canvasBorderThickness='1' showBorder='0' legendBorderAlpha='0' bgAngle='360' showlegend='0' borderColor='DEF3F3' toolTipBorderColor='cccc99' canvasPadding='0' toolTipBgColor='ffffcc' legendShadow='0' baseFontSize='12' canvasBorderAlpha='20' outCnvbaseFontSize='10' outCnvbaseFontColor='000000' numberScaleValue='10000,1,1,1000' formatNumberScale='1' palette='2' numberScaleUnit=' , ,万,千万' lineColor='AFD8F8'  ><categories  >");
		String[] dateRetStr = VelocityToolDateUtils.getSpecifiedContinusDays(
				start, end, 30, null, Globals.CONDITION_B).split(",");
		String[] dateRetStrb = VelocityToolDateUtils.getSpecifiedContinusDays(
				start, end, 30, Globals.DATE_FORMAT_B, Globals.CONDITION_B)
				.split(",");
		for (int i = 0; i < dateRetStr.length; i++) {

			xml.append("<category label='");
			xml.append(dateRetStr[i]);
			xml.append("'  />");

		}
		xml.append("</categories>");

		Map<String, String> dateMap = Collections
				.synchronizedMap(new TreeMap<String, String>());
		Map<String, TrendAnalysisDay> objectMap = new HashMap<String, TrendAnalysisDay>();

		for (TrendAnalysisDay day : trendAnalysisDayList) {
			objectMap.put(Globals.FORMAT_TYPE_B.format(day.getTrendDay()), day);
		}

		// if exists
		if (keys.indexOf("pv") != -1) {
			xml.append(pv);
			// 拼成原始串
			for (int i = 0; i < dateRetStrb.length; i++) {
				dateMap.put(dateRetStrb[i], "<set  value='0' toolText='PV: 0 "
						+ dateRetStr[i] + "'  />");
			}

			for (Entry<String, String> entry : dateMap.entrySet()) {
				String key = entry.getKey();
				if (objectMap.containsKey(key)) {
					String dataValue = entry.getValue();
					TrendAnalysisDay day = objectMap.get(key);
					String newValue = dataValue.replace(
							"value='0' toolText='PV: 0",
							"value='" + day.getPageView() + "'toolText='PV: "
									+ day.getPageView());
					// 渲染
					dateMap.put(key, newValue);
				}
			}
			xml.append(handleMap(dateMap));
			// clear
			dateMap.clear();
			xml.append("</dataset>");
		}
		if (keys.indexOf("ip") != -1) {
			xml.append(ip);

			for (int i = 0; i < dateRetStrb.length; i++) {
				dateMap.put(dateRetStrb[i], "<set  value='0' toolText='IP: 0 "
						+ dateRetStr[i] + "'  />");
			}

			for (Entry<String, String> entry : dateMap.entrySet()) {
				String key = entry.getKey();
				if (objectMap.containsKey(key)) {
					String dataValue = entry.getValue();
					TrendAnalysisDay day = objectMap.get(key);
					String newValue = dataValue.replace(
							"value='0' toolText='IP: 0",
							"value='" + day.getIp() + "'toolText='IP: "
									+ day.getIp());
					// 渲染
					dateMap.put(key, newValue);
				}
			}
			xml.append(handleMap(dateMap));
			dateMap.clear();

			xml.append("</dataset>");

		}
		if (keys.indexOf("uv") != -1) {

			xml.append(uv);
			for (int i = 0; i < dateRetStrb.length; i++) {
				dateMap.put(dateRetStrb[i],
						"<set  value='0' toolText='独立访客: 0 " + dateRetStr[i]
								+ "'  />");
			}
			for (Entry<String, String> entry : dateMap.entrySet()) {
				String key = entry.getKey();
				if (objectMap.containsKey(key)) {
					String dataValue = entry.getValue();
					TrendAnalysisDay day = objectMap.get(key);
					String newValue = dataValue
							.replace("value='0' toolText='独立访客: 0", "value='"
									+ day.getUniqueHost() + "'toolText='独立访客: "
									+ day.getUniqueHost());
					// 渲染
					dateMap.put(key, newValue);
				}
			}
			xml.append(handleMap(dateMap));
			dateMap.clear();
			xml.append("</dataset>");
		}
		if (keys.indexOf("newuser") != -1) {
			xml.append(nuv);
			for (int i = 0; i < dateRetStrb.length; i++) {
				dateMap.put(dateRetStrb[i],
						"<set  value='0' toolText='新独立访客: 0 " + dateRetStr[i]
								+ "'  />");
			}
			for (Entry<String, String> entry : dateMap.entrySet()) {
				String key = entry.getKey();
				if (objectMap.containsKey(key)) {
					String dataValue = entry.getValue();
					TrendAnalysisDay day = objectMap.get(key);
					String newValue = dataValue.replace(
							"value='0' toolText='新独立访客: 0",
							"value='" + day.getNewUniqueHost()
									+ "'toolText='新独立访客: "
									+ day.getNewUniqueHost());
					// 渲染
					dateMap.put(key, newValue);
				}
			}
			xml.append(handleMap(dateMap));
			dateMap.clear();
			xml.append("</dataset>");
		}
		xml.append(tail);
		// System.out.println(xml.toString());
		return xml.toString();
	}

	// 对map拼串
	private static String handleMap(Map<String, String> map) {
		if (!(null != map && map.size() > 0))
			return null;
		StringBuffer sb = new StringBuffer();

		for (Entry<String, String> entry : map.entrySet()) {
			sb.append(entry.getValue());
		}
		return sb.toString();
	}

	/*
	 * 拼拆线图
	 * 
	 * @param beforehours
	 * 
	 * @param todayhours
	 * 
	 * @param keyid
	 * 
	 * @return
	 */
	public static String getLine(List<TrendAnalysisHour> beforehours,
			List<TrendAnalysisHour> todayhours, String keyid, String todate,
			String beforedate) {

		String type[] = keyid.split(",");
		StringBuffer xml = new StringBuffer(
				"<chart showFCMenuItem='0' lineThickness='2' showValues='0' anchorRadius='4' divLineAlpha='20' divLineColor='CC3300' divLineIsDashed='1' showAlternateHGridColor='1' alternateHGridAlpha='5' alternateHGridColor='CC3300' shadowAlpha='40' labelStep='2' numvdivlines='22' showAlternateVGridColor='1' chartsshowShadow='1' chartRightMargin='6' chartTopMargin='15' chartLeftMargin='10' chartBottomMargin='3' bgColor='FFFFFF' canvasBorderThickness='1' showBorder='0' legendBorderAlpha='0' bgAngle='360' showlegend='0' borderColor='DEF3F3' toolTipBorderColor='cccc99' canvasPadding='0' toolTipBgColor='ffffcc' legendShadow='0' baseFontSize='12' canvasBorderAlpha='20' outCnvbaseFontSize='10' outCnvbaseFontColor='000000' numberScaleValue='10000,1,1,1000' formatNumberScale='1' palette='2' numberScaleUnit=' , ,万,千万' lineColor='AFD8F8'  ><categories >");
		StringBuffer pvtoxml = new StringBuffer(
				"<dataset  seriesName='PV' color='0033CC' anchorBorderColor='0033CC'>");
		StringBuffer pvbeforexml = new StringBuffer(
				"<dataset  seriesName='PV' color='6699FF' anchorBorderColor='6699FF'>");
		StringBuffer uvtoxml = new StringBuffer(
				"<dataset  seriesName='独立访客' color='33CC33' anchorBorderColor='33CC33'>");
		StringBuffer uvbeforexml = new StringBuffer(
				"<dataset  seriesName='独立访客' color='99FF99' anchorBorderColor='99FF99'>");
		StringBuffer iptoxml = new StringBuffer(
				"<dataset  seriesName='IP' color='FF0000' anchorBorderColor='FF0000'>");
		StringBuffer ipbeforexml = new StringBuffer(
				"<dataset  seriesName='IP' color='FF9999' anchorBorderColor='FF9999'>");
		StringBuffer newuvtoxml = new StringBuffer(
				"<dataset  seriesName='新独立访客' color='ffa902' anchorBorderColor='ffa902'>");
		StringBuffer newuvbeforexml = new StringBuffer(
				"<dataset  seriesName='新独立访客' color='f0ff02' anchorBorderColor='f0ff02'>");

		for (int i = 0; i < 24; i++) {
			if (i >= 10) {
				xml.append("<category label='" + i + ":00'  />");
			} else {
				xml.append("<category label='0" + i + ":00'  />");
			}
		}
		xml.append("</categories>");

		Map<String, TrendAnalysisHour> beforemap = new HashMap<String, TrendAnalysisHour>(
				32);
		Map<String, TrendAnalysisHour> tomap = new HashMap<String, TrendAnalysisHour>(
				32);

		for (TrendAnalysisHour before : beforehours) {
			beforemap.put(before.getHour(), before);
		}
		for (TrendAnalysisHour today : todayhours) {
			tomap.put(today.getHour(), today);
		}
		Map<String, String> typemap = new HashMap<String, String>();
		for (int y = 0; y < type.length; y++) {
			typemap.put(type[y], type[y]);
		}
		Map<String, String> map = new TreeMap<String, String>();
		String key = "";
		for (int x = 0; x < 24; x++) {

			if (x < 10) {
				key = "0" + x + ":00";
			} else {
				key = x + ":00";
			}
			map.put(key, "<set  value='0' toolText='PV:0 0 0'/>");
		}
		Set<String> keys = map.keySet();
		String pv = typemap.get("pv");
		String uv = typemap.get("uv");
		String ip = typemap.get("ip");
		String newuser = typemap.get("newuser");
		for (Iterator<String> it = keys.iterator(); it.hasNext();) {
			String value = it.next();
			TrendAnalysisHour maptovalue = tomap.get(value);
			TrendAnalysisHour mapbeforevalue = beforemap.get(value);
			if (!(null == pv)) {

				if (null == maptovalue)
					pvtoxml.append("<set  value='0' toolText='PV:0 " + todate
							+ " " + value + "'/>");
				else
					pvtoxml.append("<set  value='"
							+ maptovalue.getPageView()
							+ "' toolText='PV:"
							+ maptovalue.getPageView()
							+ " "
							+ Globals.FORMAT_TYPE_A.format(maptovalue
									.getTrendDay()) + " "
							+ maptovalue.getHour() + "'/>");
				if (null == mapbeforevalue)
					pvbeforexml.append("<set  value='0' toolText='PV:0 "
							+ beforedate + " " + value + "'/>");
				else
					pvbeforexml.append("<set  value='"
							+ mapbeforevalue.getPageView()
							+ "' toolText='PV:"
							+ mapbeforevalue.getPageView()
							+ " "
							+ Globals.FORMAT_TYPE_A.format(mapbeforevalue
									.getTrendDay()) + " "
							+ mapbeforevalue.getHour() + "'/>");
			}
			if (!(null == uv)) {
				if (null == maptovalue)
					uvtoxml.append("<set  value='0' toolText='独立访客:0 " + todate
							+ " " + value + "'/>");
				else
					uvtoxml.append("<set  value='"
							+ maptovalue.getUniqueHost()
							+ "' toolText='独立访客:"
							+ maptovalue.getUniqueHost()
							+ " "
							+ Globals.FORMAT_TYPE_A.format(maptovalue
									.getTrendDay()) + " "
							+ maptovalue.getHour() + "'/>");
				if (null == mapbeforevalue)
					uvbeforexml.append("<set  value='0' toolText='独立访客:0 "
							+ beforedate + " " + value + "'/>");
				else
					uvbeforexml.append("<set  value='"
							+ mapbeforevalue.getUniqueHost()
							+ "' toolText='独立访客:"
							+ mapbeforevalue.getUniqueHost()
							+ " "
							+ Globals.FORMAT_TYPE_A.format(mapbeforevalue
									.getTrendDay()) + " "
							+ mapbeforevalue.getHour() + "'/>");
			}
			if (!(null == ip)) {
				if (null == maptovalue)
					iptoxml.append("<set  value='0' toolText='IP:0 " + todate
							+ " " + value + "'/>");
				else
					iptoxml.append("<set  value='"
							+ maptovalue.getIp()
							+ "' toolText='IP:"
							+ maptovalue.getIp()
							+ " "
							+ Globals.FORMAT_TYPE_A.format(maptovalue
									.getTrendDay()) + " "
							+ maptovalue.getHour() + "'/>");
				if (null == mapbeforevalue)
					ipbeforexml.append("<set  value='0' toolText='IP:0 "
							+ beforedate + " " + value + "'/>");
				else
					ipbeforexml.append("<set  value='"
							+ mapbeforevalue.getIp()
							+ "' toolText='IP:"
							+ mapbeforevalue.getIp()
							+ " "
							+ Globals.FORMAT_TYPE_A.format(mapbeforevalue
									.getTrendDay()) + " "
							+ mapbeforevalue.getHour() + "'/>");
			}
			if (!(null == newuser)) {
				if (null == maptovalue)
					newuvtoxml.append("<set  value='0' toolText='新独立访客:0 "
							+ todate + " " + value + "'/>");
				else
					newuvtoxml.append("<set  value='"
							+ maptovalue.getNewUniqueHost()
							+ "' toolText='新独立访客:"
							+ maptovalue.getNewUniqueHost()
							+ " "
							+ Globals.FORMAT_TYPE_A.format(maptovalue
									.getTrendDay()) + " "
							+ maptovalue.getHour() + "'/>");
				if (null == mapbeforevalue)
					newuvbeforexml.append("<set  value='0' toolText='新独立访客:0 "
							+ beforedate + " " + value + "'/>");
				else
					newuvbeforexml.append("<set  value='"
							+ mapbeforevalue.getNewUniqueHost()
							+ "' toolText='新独立访客:"
							+ mapbeforevalue.getNewUniqueHost()
							+ " "
							+ Globals.FORMAT_TYPE_A.format(mapbeforevalue
									.getTrendDay()) + " "
							+ mapbeforevalue.getHour() + "'/>");
			}
		}
		pvtoxml.append("</dataset>");
		pvbeforexml.append("</dataset>");
		uvtoxml.append("</dataset>");
		uvbeforexml.append("</dataset>");
		iptoxml.append("</dataset>");
		ipbeforexml.append("</dataset>");
		newuvtoxml.append("</dataset>");
		newuvbeforexml.append("</dataset>");
		xml.append(pvtoxml).append(pvbeforexml).append(uvtoxml)
				.append(uvbeforexml).append(iptoxml).append(ipbeforexml)
				.append(newuvtoxml).append(newuvbeforexml);
		xml.append("<styles><definition><style name='CaptionFont' type='font' size='12'  /><style name='myLegendFont' type='font' size='11'  /></definition><application><apply toObject='CAPTION' styles='CaptionFont'  /><apply toObject='SUBCAPTION' styles='CaptionFont'  /><apply toObject='Legend' styles='myLegendFont'  /></application></styles></chart>");
		return xml.toString();
	}

	/*
	 * 拼饼状图
	 * 
	 * @param referDomain域名总汇
	 * 
	 * @param beforeDate开始日期
	 * 
	 * @param toDate结束日期
	 * 
	 * @return
	 */
	public static String getpie(Map<String, String> referDomain,
			String beforeDate, String toDate) {
		StringBuffer xml = new StringBuffer(
				"<chart showFCMenuItem='0' toolTipSepChar=': ' numberScaleUnit=' , ,万,千万' formatNumberScale='1' numberScaleValue='10000,1,1,1000' palette='4' bgColor='666666' showPercentageValues='0' use3DLighting='1' chartsshowShadow='0' subcaption='");
		xml.append(beforeDate).append(" - ");
		xml.append(toDate)
				.append("' caption='来路域名-按来访次数查询' showShadow='0' bgAlpha='0' baseFontSize='12' baseFontColor='000000' bgAngle='360' showBorder='0' pieRadius='90'  >");
		for (Iterator<String> iterator = referDomain.keySet().iterator(); iterator
				.hasNext();) {
			String key = (String) iterator.next();
			String value = referDomain.get(key);
			xml.append("<set  value='" + value + "' label='" + key + "'  />");
		}
		xml.append("<styles><definition><style name='CaptionFont' type='font' bold='0' size='12'  /></definition><application><apply toObject='subcaption' styles='CaptionFont'  /></application></styles></chart>");
		return xml.toString();
	}

	public static String getLineByDomain(List<ReferCategory> categoryList,
			String keyid, String formDate, String toDate) throws ParseException {
		String type[] = keyid.split(",");
		StringBuffer xml = new StringBuffer(
				"<chart lineThickness='2' showValues='0' anchorRadius='4' divLineAlpha='20' divLineColor='CC3300' divLineIsDashed='1' showAlternateHGridColor='1' alternateHGridAlpha='5' alternateHGridColor='CC3300' shadowAlpha='40' labelStep='4' numvdivlines='25' showAlternateVGridColor='1' chartsshowShadow='1' chartRightMargin='20' chartTopMargin='0' chartLeftMargin='0' chartBottomMargin='0' bgColor='FFFFFF' canvasBorderThickness='1' showBorder='0' legendBorderAlpha='0' bgAngle='360' showlegend='0' borderColor='DEF3F3' toolTipBorderColor='cccc99' canvasPadding='0' toolTipBgColor='ffffcc' legendShadow='0' baseFontSize='12' canvasBorderAlpha='20' outCnvbaseFontSize='10' outCnvbaseFontColor='000000' numberScaleValue='10000,1,1,1000' caption='来路分类（"
						+ formDate
						+ "-"
						+ toDate
						+ "）' palette='2' numberScaleUnit=' , ,万,千万' lineColor='AFD8F8'  ><categories>");
		StringBuffer enginexml = new StringBuffer(
				"<dataset  seriesName='搜索引擎' color='7128de' anchorBorderColor='7128de'  >");
		StringBuffer externalxml = new StringBuffer(
				"<dataset  seriesName='其他外部链接' color='ff6e00' anchorBorderColor='ff6e00'  >");
		StringBuffer directxml = new StringBuffer(
				"<dataset  seriesName='直接输入网址或书签' color='00a8e5' anchorBorderColor='00a8e5'  >");

		Map<String, ReferCategory> tomap = new HashMap<String, ReferCategory>(
				32);
		Map<String, String> map = new TreeMap<String, String>();
		String key = "";
		if (formDate.equals(toDate)) {
			for (int i = 0; i < 24; i++) {
				if (i >= 10) {
					xml.append("<category label='" + formDate + " " + i
							+ ":00'  />");
				} else {
					xml.append("<category label='" + formDate + " 0" + i
							+ ":00'  />");
				}
			}
			for (ReferCategory today : categoryList) {
				tomap.put(today.getHour(), today);
			}
			for (int x = 0; x < 24; x++) {

				if (x < 10) {
					key = "0" + x + ":00";
				} else {
					key = x + ":00";
				}
				map.put(key, "<set  value='0' tooltext='0: 0次来访 0 0'  />");
			}
		} else {
			for (ReferCategory today : categoryList) {
				tomap.put(Globals.FORMAT_TYPE_A.format(today.getReferDate()),
						today);
			}
			String f = formDate;
			String t = toDate;
			map.put(f, "<set  value='0' tooltext='0: 0次来访 0 0'  />");
			map.put(t, "<set  value='0' tooltext='0: 0次来访 0 0'  />");
			while (!f.equals(t)) {
				xml.append("<category label='" + f + "'  />");
				f = Globals.FORMAT_TYPE_A.format(Globals.FORMAT_TYPE_A.parse(f)
						.getTime() + 1 * 24 * 3600 * 1000);
				map.put(f, "<set  value='0' tooltext='0: 0次来访 0 0'  />");
			}
			xml.append("<category label='" + t + "'  />");
		}

		xml.append("</categories>");

		Map<String, String> typemap = new HashMap<String, String>();
		for (int y = 0; y < type.length; y++) {
			typemap.put(type[y], type[y]);
		}

		// Set<String> keys = new TreeSet<String>();
		// keys = map.keySet();
		String engine = typemap.get("engineId");
		String external = typemap.get("externalId");
		String direct = typemap.get("directId");
		for (Entry<String, String> entry : map.entrySet()) {
			String k = entry.getKey();
			ReferCategory maptovalue = tomap.get(k);
			if (null != maptovalue) {
				if (null == maptovalue.getHour()) {
					if (!(null == engine)) {
						enginexml.append("<set  value='"
								+ maptovalue.getEngineCount()
								+ "' tooltext='搜索引擎: "
								+ maptovalue.getEngineCount()
								+ "次来访 "
								+ Globals.FORMAT_TYPE_A.format(maptovalue
										.getReferDate()) + "' />");
					}
					if (!(null == external)) {
						externalxml.append("<set  value='"
								+ maptovalue.getExternalCount()
								+ "' tooltext='其他外部链接: "
								+ maptovalue.getExternalCount()
								+ "次来访"
								+ Globals.FORMAT_TYPE_A.format(maptovalue
										.getReferDate()) + "'  />");
					}
					if (!(null == direct)) {

						directxml.append("<set  value='"
								+ maptovalue.getDirectCount()
								+ "' tooltext='直接输入网址或书签: "
								+ maptovalue.getDirectCount()
								+ "次来访"
								+ Globals.FORMAT_TYPE_A.format(maptovalue
										.getReferDate()) + "'  />");
					}

				} else {
					if (!(null == engine)) {

						enginexml.append("<set  value='"
								+ maptovalue.getEngineCount()
								+ "' tooltext='搜索引擎: "
								+ maptovalue.getEngineCount()
								+ "次来访 "
								+ Globals.FORMAT_TYPE_A.format(maptovalue
										.getReferDate()) + " "
								+ maptovalue.getHour() + "' />");

					}
					if (!(null == external)) {

						externalxml.append("<set  value='"
								+ maptovalue.getExternalCount()
								+ "' tooltext='其他外部链接: "
								+ maptovalue.getExternalCount()
								+ "次来访"
								+ Globals.FORMAT_TYPE_A.format(maptovalue
										.getReferDate()) + " "
								+ maptovalue.getHour() + "'  />");
					}
					if (!(null == direct)) {
						directxml.append("<set  value='"
								+ maptovalue.getDirectCount()
								+ "' tooltext='直接输入网址或书签: "
								+ maptovalue.getDirectCount()
								+ "次来访"
								+ Globals.FORMAT_TYPE_A.format(maptovalue
										.getReferDate()) + " "
								+ maptovalue.getHour() + "'  />");

					}
				}
			} else {
				if (!(null == engine)) {
					if (formDate.equals(toDate)) {
						enginexml
								.append("<set  value='0' tooltext='搜索引擎: 0次来访 "
										+ formDate + " " + k + "' />");
					} else {
						enginexml
								.append("<set  value='0' tooltext='搜索引擎: 0次来访 "
										+ k + "' />");
					}
				}
				if (!(null == external)) {
					if (formDate.equals(toDate)) {
						externalxml
								.append("<set  value='0' tooltext='其他外部链接: 0次来访 "
										+ formDate + " " + k + "' />");
					} else {
						externalxml
								.append("<set  value='0' tooltext='其他外部链接: 0次来访 "
										+ k + "' />");
					}
				}
				if (!(null == direct)) {
					if (formDate.equals(toDate)) {
						directxml
								.append("<set  value='0' tooltext='直接输入网址或书签: 0次来访 "
										+ formDate + " " + k + "' />");
					} else {
						directxml
								.append("<set  value='0' tooltext='直接输入网址或书签: 0次来访 "
										+ k + "' />");
					}
				}
			}
		}
		enginexml.append("</dataset>");
		externalxml.append("</dataset>");
		directxml.append("</dataset>");
		xml.append(enginexml).append(externalxml).append(directxml);
		xml.append("<styles><definition><style name='CaptionFont' type='font' size='12'  /><style name='datasetFont' type='font' size='12'  /><style name='myHTMLFont' type='font' size='12' isHTML='1'  /></definition><application><apply toObject='CAPTION' styles='CaptionFont'  /><apply toObject='seriesName' styles='datasetFont'  /><apply toObject='TOOLTIP' styles='myHTMLFont'  /></application></styles></chart>");
		// System.out.println(xml.toString());
		return xml.toString();
	}

	public static String getOnline(List<FlowisStatDetailDTO> flowList, Date date)
			throws ParseException {
		StringBuffer xml = new StringBuffer(
				"<chart showFCMenuItem='0' lineThickness='2' showValues='0' anchorRadius='4' divLineAlpha='20' divLineColor='CC3300' divLineIsDashed='1' showAlternateHGridColor='1' alternateHGridAlpha='5' alternateHGridColor='CC3300' shadowAlpha='40' labelStep='1' numvdivlines='13' showAlternateVGridColor='1' chartsshowShadow='1' chartRightMargin='20' chartTopMargin='15' chartLeftMargin='10' chartBottomMargin='3' bgColor='FFFFFF' canvasBorderThickness='1' showBorder='0' legendBorderAlpha='0' bgAngle='360' showlegend='1' borderColor='DEF3F3' toolTipBorderColor='cccc99' canvasPadding='0' toolTipBgColor='ffffcc' legendShadow='0' baseFontSize='12' canvasBorderAlpha='20' outCnvbaseFontSize='10' outCnvbaseFontColor='000000' numberScaleValue='10000,1,1,1000' formatNumberScale='1' palette='2' numberScaleUnit=' , ,万,千万' animation='0' lineColor='AFD8F8'  ><categories  >");
		StringBuffer pvxml = new StringBuffer(
				"<dataset  seriesName='PV' color='0033CC' anchorBorderColor='0033CC'  >");
		StringBuffer ipxml = new StringBuffer(
				"<dataset  seriesName='IP' color='FF0000' anchorBorderColor='FF0000'  >");

		Map<String, FlowisStatDetailDTO> tomap = new HashMap<String, FlowisStatDetailDTO>(
				18);
		Map<String, String> map = new TreeMap<String, String>();

		for (int i = 15; i >= 1; i--) {

			String dateFormat = Globals.FORMAT_TYPE_C
					.format(VelocityToolDateUtils.format
							.parse(VelocityToolDateUtils.format.format(date
									.getTime() - i * 60 * 1000)));
			xml.append("<category label='" + dateFormat + "' />");
			map.put(dateFormat, "<set  value='0' toolText='0 IP: 0'  />");
		}
		for (FlowisStatDetailDTO today : flowList) {
			tomap.put(Globals.FORMAT_TYPE_C.format(VelocityToolDateUtils.format
					.parse(today.getAccess_date())), today);
		}
		xml.append("</categories>");

		for (Entry<String, String> entry : map.entrySet()) {
			String k = entry.getKey();
			FlowisStatDetailDTO maptovalue = tomap.get(k);
			if (null != maptovalue) {
				pvxml.append("<set  value='" + maptovalue.getPv()
						+ "' toolText='" + k + " PV: " + maptovalue.getPv()
						+ "'  />");
				ipxml.append("<set  value='" + maptovalue.getIpCount()
						+ "' toolText='" + k + " IP: "
						+ maptovalue.getIpCount() + "'  />");
			} else {
				pvxml.append("<set  value='0' toolText='" + k + " PV: 0'  />");
				ipxml.append("<set  value='0' toolText='" + k + " IP: 0'  />");
			}
		}
		pvxml.append("</dataset>");
		ipxml.append("</dataset>");
		xml.append(pvxml).append(ipxml);
		xml.append("<styles><definition><style name='CaptionFont' type='font' size='12'  /><style name='myLegendFont' type='font' size='11'  /></definition><application><apply toObject='CAPTION' styles='CaptionFont'  /><apply toObject='SUBCAPTION' styles='CaptionFont'  /><apply toObject='Legend' styles='myLegendFont'  /></application></styles></chart>");
		// System.out.println(xml);
		return xml.toString();
	}

	public static String getColumnByDomain(List<ReferDomain> domainList,
			String value, String fromDate, String toDate) throws ParseException {
		StringBuffer xml = new StringBuffer(
				"<chart showFCMenuItem='0' palette='2' caption=' ["
						+ fromDate
						+ "]  至  ["
						+ toDate
						+ "]   ' canvasBorderAlpha='20' bgColor='FFFFFF' canvasBorderThickness='1' showBorder='0' legendBorderAlpha='0' bgAngle='360' showlegend='1' showValues='1' decimals='2' useRoundEdges='0' baseFontSize ='9' outCnvbaseFontSize='10' use3DLighting='0' numberScaleValue='10000,1,1,1000' formatNumberScale='1' numberScaleUnit=' , ,万,千万 ' toolTipSepChar='：  ' plotFillRatio='100,0' chartRightMargin='6' chartTopMargin='0' chartLeftMargin='0' chartBottomMargin='3' showShadow='0' labelStep='2' animation='0'>");
		String f = fromDate;
		String t = toDate;
		Map<String, ReferDomain> tomap = new HashMap<String, ReferDomain>();
		for (ReferDomain domain : domainList) {
			tomap.put(Globals.FORMAT_TYPE_A.format(domain.getReferDate()),
					domain);
		}
		Map<String, String> map = new TreeMap<String, String>();
		map.put(f, "<set label='0' value='0' toolText='0'/>");
		while (!f.equals(t)) {
			f = Globals.FORMAT_TYPE_A.format(Globals.FORMAT_TYPE_A.parse(f)
					.getTime() + 1 * 24 * 3600 * 1000);
			map.put(f, "0");
		}
		map.put(t, "<set label='0' value='0' toolText='0'/>");
		for (Entry<String, String> entry : map.entrySet()) {
			String k = entry.getKey();
			ReferDomain maptovalue = tomap.get(k);
			if (null != maptovalue) {
				if (value.equals("pv")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getVisitCount() + "' toolText='来访次数: "
							+ maptovalue.getVisitCount() + "'/>");
				}
				if (value.equals("uv")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getUniqueHost() + "' toolText='独立访客: "
							+ maptovalue.getUniqueHost() + "'/>");
				}
				if (value.equals("ipv")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getIp() + "' toolText='IP: "
							+ maptovalue.getIp() + "'/>");
				}
				if (value.equals("nuv")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getNewUniqueHost()
							+ "' toolText='新独立访客: "
							+ maptovalue.getNewUniqueHost() + "'/>");
				}
				if (value.equals("npv")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getNewUniqueHostCount()
							+ "' toolText='新访客浏览次数: "
							+ maptovalue.getNewUniqueHostCount() + "'/>");
				}
				if (value.equals("tpv")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getStandCount()
							+ "' toolText='站内总浏览次数: "
							+ maptovalue.getStandCount() + "'/>");
				}
			} else {

				if (value.equals("pv")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='来访次数: 0'/>");
				}
				if (value.equals("uv")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='独立访客: 0'/>");
				}
				if (value.equals("ipv")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='IP: 0'/>");
				}
				if (value.equals("nuv")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='新独立访客: 0'/>");
				}
				if (value.equals("npv")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='新访客浏览次数: 0'/>");
				}
				if (value.equals("tpv")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='站内总浏览次数: 0'/>");
				}
			}
		}
		xml.append("<styles><definition><style name='CaptionFont' type='font' size='12' /></definition><application><apply toObject='caption' styles='CaptionFont' /></application></styles></chart>");
		return xml.toString();
	}

	public static String getColumnByPage(List<ReferPage> pageList,
			String value, String fromDate, String toDate) throws ParseException {
		StringBuffer xml = new StringBuffer(
				"<chart showFCMenuItem='0' palette='2' caption=' ["
						+ fromDate
						+ "]  至  ["
						+ toDate
						+ "]   ' canvasBorderAlpha='20' bgColor='FFFFFF' canvasBorderThickness='1' showBorder='0' legendBorderAlpha='0' bgAngle='360' showlegend='1' showValues='1' decimals='2' useRoundEdges='0' baseFontSize ='9' outCnvbaseFontSize='10' use3DLighting='0' numberScaleValue='10000,1,1,1000' formatNumberScale='1' numberScaleUnit=' , ,万,千万 ' toolTipSepChar='：  ' plotFillRatio='100,0' chartRightMargin='6' chartTopMargin='0' chartLeftMargin='0' chartBottomMargin='3' showShadow='0' labelStep='2' animation='0'>");
		String f = fromDate;
		String t = toDate;
		Map<String, ReferPage> tomap = new HashMap<String, ReferPage>();
		for (ReferPage page : pageList) {
			tomap.put(Globals.FORMAT_TYPE_A.format(page.getReferDate()), page);
		}
		Map<String, String> map = new TreeMap<String, String>();
		map.put(f, "<set label='0' value='0' toolText='0'/>");
		while (!f.equals(t)) {
			f = Globals.FORMAT_TYPE_A.format(Globals.FORMAT_TYPE_A.parse(f)
					.getTime() + 1 * 24 * 3600 * 1000);
			map.put(f, "0");
		}
		map.put(t, "<set label='0' value='0' toolText='0'/>");
		for (Entry<String, String> entry : map.entrySet()) {
			String k = entry.getKey();
			ReferPage maptovalue = tomap.get(k);
			if (null != maptovalue) {
				if (value.equals("pv")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getVisitCount() + "' toolText='来访次数: "
							+ maptovalue.getVisitCount() + "'/>");
				}
				if (value.equals("uv")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getUniqueHost() + "' toolText='独立访客: "
							+ maptovalue.getUniqueHost() + "'/>");
				}
				if (value.equals("ipv")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getIp() + "' toolText='IP: "
							+ maptovalue.getIp() + "'/>");
				}
				if (value.equals("nuv")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getNewUniqueHost()
							+ "' toolText='新独立访客: "
							+ maptovalue.getNewUniqueHost() + "'/>");
				}
				if (value.equals("npv")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getNewUniqueHostCount()
							+ "' toolText='新访客浏览次数: "
							+ maptovalue.getNewUniqueHostCount() + "'/>");
				}
				if (value.equals("tpv")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getStandCount()
							+ "' toolText='站内总浏览次数: "
							+ maptovalue.getStandCount() + "'/>");
				}
			} else {

				if (value.equals("pv")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='来访次数: 0'/>");
				}
				if (value.equals("uv")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='独立访客: 0'/>");
				}
				if (value.equals("ipv")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='IP: 0'/>");
				}
				if (value.equals("nuv")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='新独立访客: 0'/>");
				}
				if (value.equals("npv")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='新访客浏览次数: 0'/>");
				}
				if (value.equals("tpv")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='站内总浏览次数: 0'/>");
				}
			}
		}
		xml.append("<styles><definition><style name='CaptionFont' type='font' size='12' /></definition><application><apply toObject='caption' styles='CaptionFont' /></application></styles></chart>");
		return xml.toString();
	}

	public static String getColumnByCategory(List<ReferCategory> categoryList,
			String value, String fromDate, String toDate) throws ParseException {
		StringBuffer xml = new StringBuffer(
				"<chart showFCMenuItem='0' palette='2' caption=' ["
						+ fromDate
						+ "]  至  ["
						+ toDate
						+ "]   ' canvasBorderAlpha='20' bgColor='FFFFFF' canvasBorderThickness='1' showBorder='0' legendBorderAlpha='0' bgAngle='360' showlegend='1' showValues='1' decimals='2' useRoundEdges='0' baseFontSize ='9' outCnvbaseFontSize='10' use3DLighting='0' numberScaleValue='10000,1,1,1000' formatNumberScale='1' numberScaleUnit=' , ,万,千万 ' toolTipSepChar='：  ' plotFillRatio='100,0' chartRightMargin='6' chartTopMargin='0' chartLeftMargin='0' chartBottomMargin='3' showShadow='0' labelStep='2' animation='0'>");
		String f = fromDate;
		String t = toDate;
		Map<String, ReferCategory> tomap = new HashMap<String, ReferCategory>();
		for (ReferCategory category : categoryList) {
			tomap.put(Globals.FORMAT_TYPE_A.format(category.getReferDate()),
					category);
		}
		Map<String, String> map = new TreeMap<String, String>();
		map.put(f, "<set label='0' value='0' toolText='0'/>");
		while (!f.equals(t)) {
			f = Globals.FORMAT_TYPE_A.format(Globals.FORMAT_TYPE_A.parse(f)
					.getTime() + 1 * 24 * 3600 * 1000);
			map.put(f, "0");
		}
		map.put(t, "<set label='0' value='0' toolText='0'/>");
		for (Entry<String, String> entry : map.entrySet()) {
			String k = entry.getKey();
			ReferCategory maptovalue = tomap.get(k);
			if (null != maptovalue) {
				if (value.equals("eg")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getEngineCount()
							+ "' toolText='搜索引擎: "
							+ maptovalue.getEngineCount() + "'/>");
				}
				if (value.equals("ec")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getExternalCount()
							+ "' toolText='外部链接: "
							+ maptovalue.getExternalCount() + "'/>");
				}
				if (value.equals("dc")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getDirectCount()
							+ "' toolText='直接输入: "
							+ maptovalue.getDirectCount() + "'/>");
				}

			} else {

				if (value.equals("eg")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='搜索引擎: 0'/>");
				}
				if (value.equals("ec")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='外部链接: 0'/>");
				}
				if (value.equals("dc")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='直接输入: 0'/>");
				}
			}
		}
		xml.append("<styles><definition><style name='CaptionFont' type='font' size='12' /></definition><application><apply toObject='caption' styles='CaptionFont' /></application></styles></chart>");
		return xml.toString();
	}

	public static String getVisitAreaMap(Map<String, Integer> visitMap,
			Integer maxValue) {
		StringBuffer xml = new StringBuffer(
				"<map showFCMenuItem='0' numberPrefix='' baseFontSize='12' animation='1' legendShadow='1'  canvasBorderThickness='0' canvasBorderAlpha='0' showBorder='0' showShadow='1' showBevel='0' showLabels='0'  fillAlpha='100' hoverColor='639ACE' bgColor='f3fbff' chartRightMargin='0' fillColor='ffffff' chartTopMargin='0' showlegend='0' chartLeftMargin='0' chartBottomMargin='0'><colorRange>");
		long value = Long.valueOf(maxValue + "0");
		if (value == 0)
			value = 1000;
		xml.append("<color minValue='1' maxValue='" + value
				+ "' color='ffff00' />");
		xml.append("<color minValue='" + value + "' maxValue='" + value * 2
				+ "' displayValue='1000-2000PV' color='ffcc00' />");
		xml.append("<color minValue='" + value * 2 + "' maxValue='" + value * 3
				+ "' displayValue='2000-5000PV' color='ff9900' />");
		xml.append("<color minValue='" + value * 3 + "' maxValue='" + value * 4
				+ "' displayValue='2000-5000PV' color='ff6600' />");
		xml.append("<color minValue='" + value * 4 + "' maxValue='" + value * 4
				* 2 + "' displayValue='2000-5000PV' color='ff3300' />");
		xml.append("<color minValue='" + value * 4 * 2 + "' maxValue='" + value
				* 4 * 3 + 1 + "' displayValue='2000-5000PV' color='ff0000' />");
		xml.append("</colorRange><data>");
		xml.append("<entity id='CN.BJ' tooltext='北京市 &lt;BR&gt;浏览次数: "
				+ visitMap.get("北京市") + "' Value='"
				+ Long.valueOf(visitMap.get("北京市") + "00") + "'  />");
		xml.append("<entity id='CN.HB' tooltext='河北省 &lt;BR&gt;浏览次数: "
				+ visitMap.get("河北省") + "' Value='"
				+ Long.valueOf(visitMap.get("河北省") + "00") + "'  />");
		xml.append("<entity id='CN.TJ' tooltext='天津市 &lt;BR&gt;浏览次数: "
				+ visitMap.get("天津市") + "' Value='"
				+ Long.valueOf(visitMap.get("天津市") + "00") + "'  />");
		xml.append("<entity id='CN.GD' tooltext='广东省 &lt;BR&gt;浏览次数: "
				+ visitMap.get("广东省") + "' Value='"
				+ Long.valueOf(visitMap.get("广东省") + "00") + "'  />");
		xml.append("<entity id='CN.GX' tooltext='广西壮族自治区 &lt;BR&gt;浏览次数: "
				+ visitMap.get("广西") + "' Value='"
				+ Long.valueOf(visitMap.get("广西") + "00") + "'  />");
		xml.append("<entity id='CN.NM' tooltext='内蒙古自治区 &lt;BR&gt;浏览次数: "
				+ visitMap.get("内蒙古") + "' Value='"
				+ Long.valueOf(visitMap.get("内蒙古") + "00") + "'  />");
		xml.append("<entity id='CN.AH' tooltext='安徽省 &lt;BR&gt;浏览次数: "
				+ visitMap.get("安徽省") + "' Value='"
				+ Long.valueOf(visitMap.get("安徽省") + "00") + "'  />");
		xml.append("<entity id='CN.CQ' tooltext='重庆市 &lt;BR&gt;浏览次数: "
				+ visitMap.get("重庆市") + "' Value='"
				+ Long.valueOf(visitMap.get("重庆市") + "00") + "'  />");
		xml.append("<entity id='CN.FJ' tooltext='福建省 &lt;BR&gt;浏览次数: "
				+ visitMap.get("福建省") + "' Value='"
				+ Long.valueOf(visitMap.get("福建省") + "00") + "'  />");
		xml.append("<entity id='CN.GS' tooltext='甘肃省 &lt;BR&gt;浏览次数: "
				+ visitMap.get("甘肃省") + "' Value='"
				+ Long.valueOf(visitMap.get("甘肃省") + "00") + "'  />");
		xml.append("<entity id='CN.GZ' tooltext='贵州省 &lt;BR&gt;浏览次数: "
				+ visitMap.get("贵州省") + "' Value='"
				+ Long.valueOf(visitMap.get("贵州省") + "00") + "'  />");
		xml.append("<entity id='CN.HA' tooltext='海南省 &lt;BR&gt;浏览次数: "
				+ visitMap.get("海南省") + "' Value='"
				+ Long.valueOf(visitMap.get("海南省") + "00") + "'  />");
		xml.append("<entity id='CN.HE' tooltext='河南省 &lt;BR&gt;浏览次数: "
				+ visitMap.get("河南省") + "' Value='"
				+ Long.valueOf(visitMap.get("河南省") + "00") + "'  />");
		xml.append("<entity id='CN.HU' tooltext='湖北省 &lt;BR&gt;浏览次数: "
				+ visitMap.get("湖北省") + "' Value='"
				+ Long.valueOf(visitMap.get("湖北省") + "00") + "'  />");
		xml.append("<entity id='CN.HL' tooltext='黑龙江省 &lt;BR&gt;浏览次数: "
				+ visitMap.get("黑龙江省") + "' Value='"
				+ Long.valueOf(visitMap.get("黑龙江省") + "00") + "'  />");
		xml.append("<entity id='CN.HN' tooltext='湖南省 &lt;BR&gt;浏览次数: "
				+ visitMap.get("湖南省") + "' Value='"
				+ Long.valueOf(visitMap.get("湖南省") + "00") + "'  />");
		xml.append("<entity id='CN.JS' tooltext='江苏省 &lt;BR&gt;浏览次数: "
				+ visitMap.get("江苏省") + "' Value='"
				+ Long.valueOf(visitMap.get("江苏省") + "00") + "'  />");
		xml.append("<entity id='CN.JX' tooltext='江西省 &lt;BR&gt;浏览次数: "
				+ visitMap.get("江西省") + "' Value='"
				+ Long.valueOf(visitMap.get("江西省") + "00") + "'  />");
		xml.append("<entity id='CN.JL' tooltext='吉林省 &lt;BR&gt;浏览次数: "
				+ visitMap.get("吉林省") + "' Value='"
				+ Long.valueOf(visitMap.get("吉林省") + "00") + "'  />");
		xml.append("<entity id='CN.LN' tooltext='辽宁省 &lt;BR&gt;浏览次数: "
				+ visitMap.get("辽宁省") + "' Value='"
				+ Long.valueOf(visitMap.get("辽宁省") + "00") + "'  />");
		xml.append("<entity id='CN.NX' tooltext='宁夏回族自治区 &lt;BR&gt;浏览次数: "
				+ visitMap.get("宁夏") + "' Value='"
				+ Long.valueOf(visitMap.get("宁夏") + "00") + "'  />");
		xml.append("<entity id='CN.QH' tooltext='青海省 &lt;BR&gt;浏览次数: "
				+ visitMap.get("青海省") + "' Value='"
				+ Long.valueOf(visitMap.get("青海省") + "00") + "'  />");
		xml.append("<entity id='CN.SA' tooltext='陕西省 &lt;BR&gt;浏览次数: "
				+ visitMap.get("陕西省") + "' Value='"
				+ Long.valueOf(visitMap.get("陕西省") + "00") + "'  />");
		xml.append("<entity id='CN.SD' tooltext='山东省 &lt;BR&gt;浏览次数: "
				+ visitMap.get("山东省") + "' Value='"
				+ Long.valueOf(visitMap.get("山东省") + "00") + "'  />");
		xml.append("<entity id='CN.SH' tooltext='上海市 &lt;BR&gt;浏览次数: "
				+ visitMap.get("上海市") + "' Value='"
				+ Long.valueOf(visitMap.get("上海市") + "00") + "'  />");
		xml.append("<entity id='CN.SX' tooltext='山西省 &lt;BR&gt;浏览次数: "
				+ visitMap.get("山西省") + "' Value='"
				+ Long.valueOf(visitMap.get("山西省") + "00") + "'  />");
		xml.append("<entity id='CN.SC' tooltext='四川省 &lt;BR&gt;浏览次数: "
				+ visitMap.get("四川省") + "' Value='"
				+ Long.valueOf(visitMap.get("四川省") + "00") + "'  />");
		xml.append("<entity id='CN.XJ' tooltext='新疆维吾尔族自治区 &lt;BR&gt;浏览次数: "
				+ visitMap.get("新疆") + "' Value='"
				+ Long.valueOf(visitMap.get("新疆") + "00") + "'  />");
		xml.append("<entity id='CN.XZ' tooltext='西藏 &lt;BR&gt;浏览次数: "
				+ visitMap.get("西藏") + "' Value='"
				+ Long.valueOf(visitMap.get("西藏") + "00") + "'  />");
		xml.append("<entity id='CN.YN' tooltext='云南省 &lt;BR&gt;浏览次数: "
				+ visitMap.get("云南省") + "' Value='"
				+ Long.valueOf(visitMap.get("云南省") + "00") + "'  />");
		xml.append("<entity id='CN.ZJ' tooltext='浙江省 &lt;BR&gt;浏览次数: "
				+ visitMap.get("浙江省") + "' Value='"
				+ Long.valueOf(visitMap.get("浙江省") + "00") + "'  />");
		xml.append("<entity id='CN.HK' tooltext='香港特别行政区 &lt;BR&gt;浏览次数: "
				+ visitMap.get("香港") + "' Value='"
				+ Long.valueOf(visitMap.get("香港") + "00") + "'  />");
		xml.append("<entity id='CN.MA' tooltext='澳门特别行政区 &lt;BR&gt;浏览次数: "
				+ visitMap.get("澳门") + "' Value='"
				+ Long.valueOf(visitMap.get("澳门") + "00") + "'  />");
		xml.append("<entity id='CN.TA' tooltext='台湾省 &lt;BR&gt;浏览次数: "
				+ visitMap.get("台湾省") + "' Value='"
				+ Long.valueOf(visitMap.get("台湾省") + "00") + "'  />");
		xml.append("</data><styles><definition><style name='CaptionFont' type='font' size='12'/><style name='datasetFont' type='font' size='12'/><style name='myHTMLFont' type='font' isHTML='1' /></definition><application><apply toObject='CAPTION' styles='CaptionFont' /><apply toObject='seriesName' styles='datasetFont' /><apply toObject='TOOLTIP' styles='myHTMLFont' /></application></styles></map>");
		return xml.toString();
	}

	public static String getVisitAreaPie(List<VisitArea> visitlist) {
		StringBuffer xml = new StringBuffer(
				"<chart showFCMenuItem='0' pieRadius='70' toolTipSepChar=':' caption='访客地区分布-按浏览次数查询' palette='4' bgColor='f3fbff' showPercentageValues='0' use3DLighting='1' chartsshowShadow='0' showShadow='0' bgAlpha='60' baseFontSize='12' baseFontColor='000000' chartRightMargin='0' chartLeftMargin='0' bgAngle='360' showBorder='0' numberScaleValue='10000,1,1,1000' formatNumberScale='1' numberScaleUnit=' , ,万,千万' startingAngle='0'  >");
		for (VisitArea visit : visitlist) {
			xml.append("<set  value='" + visit.getVisitCount() + "' label='"
					+ visit.getProvince() + "'  />");
		}
		xml.append("<styles><definition><style name='CaptionFont' type='font' bold='0' size='10' /></definition><application><apply toObject='subcaption' styles='CaptionFont'  /></application></styles></chart>");
		return xml.toString();
	}

	public static String getColumnByVisitArea(List<VisitArea> visitList,
			String value, String fromDate, String toDate) throws ParseException {
		StringBuffer xml = new StringBuffer(
				"<chart showFCMenuItem='0' palette='2' caption=' ["
						+ fromDate
						+ "]  至  ["
						+ toDate
						+ "]   ' canvasBorderAlpha='20' bgColor='FFFFFF' canvasBorderThickness='1' showBorder='0' legendBorderAlpha='0' bgAngle='360' showlegend='1' showValues='1' decimals='2' useRoundEdges='0' baseFontSize ='9' outCnvbaseFontSize='10' use3DLighting='0' numberScaleValue='10000,1,1,1000' formatNumberScale='1' numberScaleUnit=' , ,万,千万 ' toolTipSepChar='：  ' plotFillRatio='100,0' chartRightMargin='6' chartTopMargin='0' chartLeftMargin='0' chartBottomMargin='3' showShadow='0' labelStep='2' animation='0'>");
		String f = fromDate;
		String t = toDate;
		Map<String, VisitArea> tomap = new HashMap<String, VisitArea>();
		for (VisitArea visit : visitList) {
			tomap.put(Globals.FORMAT_TYPE_A.format(visit.getReferDate()), visit);
		}
		Map<String, String> map = new TreeMap<String, String>();
		map.put(f, "<set label='0' value='0' toolText='0'/>");
		while (!f.equals(t)) {
			f = Globals.FORMAT_TYPE_A.format(Globals.FORMAT_TYPE_A.parse(f)
					.getTime() + 1 * 24 * 3600 * 1000);
			map.put(f, "0");
		}
		map.put(t, "<set label='0' value='0' toolText='0'/>");
		for (Entry<String, String> entry : map.entrySet()) {
			String k = entry.getKey();
			VisitArea maptovalue = tomap.get(k);
			if (null != maptovalue) {
				if (value.equals("pv")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getVisitCount() + "' toolText='来访次数: "
							+ maptovalue.getVisitCount() + "'/>");
				}
				if (value.equals("uv")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getUniqueHost() + "' toolText='独立访客: "
							+ maptovalue.getUniqueHost() + "'/>");
				}
				if (value.equals("ip")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getIp() + "' toolText='IP: "
							+ maptovalue.getIp() + "'/>");
				}
				if (value.equals("nuv")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getNewUniqueHost()
							+ "' toolText='新独立访客: "
							+ maptovalue.getNewUniqueHost() + "'/>");
				}
				if (value.equals("avgc")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getAvgCount() + "' toolText='人均浏览次数: "
							+ maptovalue.getAvgCount() + "'/>");
				}
				if (value.equals("avgtime")) {
					Double avgTime = 0.0D;
					try {
						String avgTimes = StringUtil.proportion(
								String.valueOf(maptovalue.getAvgStopTime()),
								maptovalue.getVisitCount().toString(), "0.1");
						avgTime = Double.valueOf(avgTimes);
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					xml.append("<set label='" + k + "' value='" + avgTime
							+ "' toolText='平均停留时间: " + avgTime + "'/>");
				}
			} else {

				if (value.equals("pv")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='来访次数: 0'/>");
				}
				if (value.equals("uv")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='独立访客: 0'/>");
				}
				if (value.equals("ip")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='IP: 0'/>");
				}
				if (value.equals("nuv")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='新独立访客: 0'/>");
				}
				if (value.equals("avgc")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='人均浏览次数: 0'/>");
				}
				if (value.equals("avgtime")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='平均停留时间: 0'/>");
				}
			}
		}
		xml.append("<styles><definition><style name='CaptionFont' type='font' size='12' /></definition><application><apply toObject='caption' styles='CaptionFont' /></application></styles></chart>");
		return xml.toString();
	}

	public static String getOperatorPie(List<Operator> operatorList,
			String fromDate, String toDate) {
		StringBuffer xml = new StringBuffer(
				"<chart showFCMenuItem='0' toolTipSepChar=': ' numberScaleUnit=' , ,万,千万' formatNumberScale='1' numberScaleValue='10000,1,1,1000' palette='4' bgColor='666666' showPercentageValues='0' use3DLighting='1' chartsshowShadow='0' subcaption='"
						+ fromDate
						+ " - "
						+ toDate
						+ "' caption='访客接入商分布-按浏览次数查询' showShadow='0' bgAlpha='0' baseFontSize='12' baseFontColor='000000' bgAngle='360' showBorder='0'  >");
		for (int i = 0; i < operatorList.size(); i++) {
			xml.append("<set  value='" + operatorList.get(i).getVisitCount()
					+ "' label='" + operatorList.get(i).getOperatorName()
					+ "'  />");
		}
		xml.append("<styles><definition><style name='CaptionFont' type='font' bold='0' size='12'  /></definition><application><apply toObject='subcaption' styles='CaptionFont'  /></application></styles></chart>");
		return xml.toString();
	}

	public static String getOperatorMyLine(Map<String, Integer> operatorMap) {
		StringBuffer xml = new StringBuffer(
				"<chart showFCMenuItem='0' baseFontSize='12' outCnvbaseFontSize='10' legendShadow='0' numberScaleUnit=' , ,万,千万' formatNumberScale='1' numberScaleValue='10000,1,1,1000' lineThickness='1' showValues='0' anchorRadius='1' divLineAlpha='20' divLineColor='CC3300' divLineIsDashed='1' showAlternateHGridColor='1' alternateHGridAlpha='5' alternateHGridColor='CC3300' shadowAlpha='40' labelStep='1' numvdivlines='1' chartsshowShadow='0' chartRightMargin='20' chartTopMargin='15' chartLeftMargin='0' chartBottomMargin='2' bgColor='FFFFFF' legendBorderAlpha='0' bgAngle='360' showlegend='1' borderColor='DEF3F3' canvasBorderThickness='1' lineColor='AFD8F8'><categories  >");
		for (int i = 29; i >= 0; i--) {
			if (i == 28 || i == 21 || i == 14 || i == 7 || i == 0)
				xml.append("<category label='"
						+ VelocityToolDateUtils.getDayFromAt(-i)
						+ "' showLabel='1'  />");
			else
				xml.append("<category label='"
						+ VelocityToolDateUtils.getDayFromAt(-i)
						+ "' showLabel='0'  />");
		}
		xml.append("</categories><dataset  seriesName='电信'>");
		StringBuffer wangtongxml = new StringBuffer(
				"</dataset><dataset  seriesName='网通' color='F6BD0F' anchorBorderColor='F6BD0F' anchorBgColor='F6BD0F'>");
		for (int x = 29; x >= 0; x--) {
			Integer dianxin = operatorMap.get(VelocityToolDateUtils.getDay(-x)
					+ "电信");
			Integer wangtong = operatorMap.get(VelocityToolDateUtils.getDay(-x)
					+ "网通");
			if (dianxin == null) {
				xml.append("<set  value='0' toolText='电信: 0 PV "
						+ VelocityToolDateUtils.getDay(-x) + "'  />");
			}
			if (wangtong == null) {
				wangtongxml.append("<set  value='0' toolText='网通: 0 PV "
						+ VelocityToolDateUtils.getDay(-x) + "'  />");
			}
			if (dianxin != null) {
				xml.append("<set  value='" + dianxin + "' toolText='电信: "
						+ dianxin + " PV " + VelocityToolDateUtils.getDay(-x)
						+ "'  />");
			}
			if (wangtong != null) {
				wangtongxml.append("<set  value='" + wangtong
						+ "' toolText='网通: " + wangtong + " PV "
						+ VelocityToolDateUtils.getDay(-x) + "'  />");
			}

		}
		xml.append(wangtongxml);
		xml.append("</dataset><styles><definition><style name='CaptionFont' type='font' size='12'  /><style name='myLegendFont' type='font' size='12'  /></definition><application><apply toObject='CAPTION' styles='CaptionFont'  /><apply toObject='SUBCAPTION' styles='CaptionFont'  /><apply toObject='Legend' styles='myLegendFont'  /></application></styles></chart>");
		return xml.toString();
	}

	public static String getOperatorStackedArea(Map<String, Integer> operatorMap) {
		StringBuffer xml = new StringBuffer(
				"<chart showFCMenuItem='0' baseFontSize='12' outCnvbaseFontSize='10' numberScaleUnit=' , ,万,千万' formatNumberScale='1' numberScaleValue='10000,1,1,1000' bgColor='ffffff' bgborder='0' outCnvBaseFontColor='666666' showValues='0' numVDivLines='0' showAlternateVGridColor='0' showlegend='0' baseFontColor='000000' chartsshowShadow='0' canvasBorderThickness='0' borderColor='DEF3F3' showPlotBorder='0' plotFillAlpha='80' chartLeftMargin='0' chartRightMargin='20' areaBgColor='AFD8F8'><categories>");
		for (int i = 29; i >= 0; i--) {
			if (i == 28 || i == 21 || i == 14 || i == 7 || i == 0)
				xml.append("<category label='"
						+ VelocityToolDateUtils.getDayFromAt(-i)
						+ "' showLabel='1'  />");
			else
				xml.append("<category label='"
						+ VelocityToolDateUtils.getDayFromAt(-i)
						+ "' showLabel='0'  />");
		}
		xml.append("</categories><dataset  seriesName='总浏览次数' color='49acff' plotBorderColor='0067be'>");
		for (int x = 29; x >= 0; x--) {
			Integer pvcount = operatorMap.get(VelocityToolDateUtils.getDay(-x));
			if (pvcount == null) {
				xml.append("<set value='0' toolText='总访问量: 0 PV "
						+ VelocityToolDateUtils.getDay(-x) + "'/>");
			}

			if (pvcount != null) {
				xml.append("<set value='" + pvcount + "' toolText='总访问量: "
						+ pvcount + " PV " + VelocityToolDateUtils.getDay(-x)
						+ "'/>");
			}
		}
		xml.append("</dataset><styles><definition><style name='TrendAnim' type='animation' param='_alpha' duration='1' start='1'  /></definition><application><apply toObject='TRENDLINES' styles='TrendAnim'  /></application></styles></chart>");
		return xml.toString();
	}

	public static String getColumnByOperator(List<Operator> operatorList,
			String value, String fromDate, String toDate) throws ParseException {
		StringBuffer xml = new StringBuffer(
				"<chart showFCMenuItem='0' palette='2' caption=' ["
						+ fromDate
						+ "]  至  ["
						+ toDate
						+ "]   ' canvasBorderAlpha='20' bgColor='FFFFFF' canvasBorderThickness='1' showBorder='0' legendBorderAlpha='0' bgAngle='360' showlegend='1' showValues='1' decimals='2' useRoundEdges='0' baseFontSize ='9' outCnvbaseFontSize='10' use3DLighting='0' numberScaleValue='10000,1,1,1000' formatNumberScale='1' numberScaleUnit=' , ,万,千万 ' toolTipSepChar='：  ' plotFillRatio='100,0' chartRightMargin='6' chartTopMargin='0' chartLeftMargin='0' chartBottomMargin='3' showShadow='0' labelStep='2' animation='0'>");
		String f = fromDate;
		String t = toDate;
		Map<String, Operator> tomap = new HashMap<String, Operator>();
		for (Operator operator : operatorList) {
			tomap.put(Globals.FORMAT_TYPE_A.format(operator.getReferDate()),
					operator);
		}
		Map<String, String> map = new TreeMap<String, String>();
		map.put(f, "<set label='0' value='0' toolText='0'/>");
		while (!f.equals(t)) {
			f = Globals.FORMAT_TYPE_A.format(Globals.FORMAT_TYPE_A.parse(f)
					.getTime() + 1 * 24 * 3600 * 1000);
			map.put(f, "0");
		}
		map.put(t, "<set label='0' value='0' toolText='0'/>");
		for (Entry<String, String> entry : map.entrySet()) {
			String k = entry.getKey();
			Operator maptovalue = tomap.get(k);
			if (null != maptovalue) {
				if (value.equals("pv")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getVisitCount() + "' toolText='来访次数: "
							+ maptovalue.getVisitCount() + "'/>");
				}
				if (value.equals("uv")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getUniqueHost() + "' toolText='独立访客: "
							+ maptovalue.getUniqueHost() + "'/>");
				}
				if (value.equals("ip")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getIp() + "' toolText='IP: "
							+ maptovalue.getIp() + "'/>");
				}
				if (value.equals("nuv")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getNewUniqueHost()
							+ "' toolText='新独立访客: "
							+ maptovalue.getNewUniqueHost() + "'/>");
				}
				if (value.equals("avgc")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getAvgCount() + "' toolText='人均浏览次数: "
							+ maptovalue.getAvgCount() + "'/>");
				}
				if (value.equals("avgtime")) {
					Double avgTime = 0D;
					try {
						String avgTimes = StringUtil.proportion(
								String.valueOf(maptovalue.getAvgStopTime()),
								maptovalue.getVisitCount().toString(), "0.1");
						avgTime = Double.valueOf(avgTimes);
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					xml.append("<set label='" + k + "' value='" + avgTime
							+ "' toolText='平均停留时间: " + avgTime + "'/>");
				}
			} else {

				if (value.equals("pv")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='来访次数: 0'/>");
				}
				if (value.equals("uv")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='独立访客: 0'/>");
				}
				if (value.equals("ip")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='IP: 0'/>");
				}
				if (value.equals("nuv")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='新独立访客: 0'/>");
				}
				if (value.equals("avgc")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='人均浏览次数: 0'/>");
				}
				if (value.equals("avgtime")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='平均停留时间: 0'/>");
				}
			}
		}
		xml.append("<styles><definition><style name='CaptionFont' type='font' size='12' /></definition><application><apply toObject='caption' styles='CaptionFont' /></application></styles></chart>");
		return xml.toString();
	}

	public static String getModulePie(List<Module> moduleList, String fromDate,
			String toDate) throws IOException, ParseException {
		toDate = Globals.FORMAT_TYPE_A.format(Globals.FORMAT_TYPE_A.parse(
				toDate).getTime()
				- 1 * 24 * 3600 * 1000);
		StringBuffer xml = new StringBuffer(
				"<chart showFCMenuItem='0' toolTipSepChar=': ' numberScaleUnit=' , ,万,千万' formatNumberScale='1' numberScaleValue='10000,1,1,1000' palette='4' bgColor='666666' showPercentageValues='0' use3DLighting='1' chartsshowShadow='0' subcaption='"
						+ fromDate
						+ " - "
						+ toDate
						+ "' caption='模块-按浏览次数查询' showShadow='0' bgAlpha='0' baseFontSize='12' baseFontColor='000000' bgAngle='360' showBorder='0' pieRadius='90'  >");
		for (int i = 0; i < moduleList.size(); i++) {
			xml.append("<set  value='"
					+ moduleList.get(i).getVisitCount()
					+ "' label='"
					+ StringUtil.getModule(moduleList.get(i).getModuleName()
							.toString()) + "'  />");
		}
		xml.append("<styles><definition><style name='CaptionFont' type='font' bold='0' size='12'  /></definition><application><apply toObject='subcaption' styles='CaptionFont'  /></application></styles></chart>");
		return xml.toString();
	}

	public static String getColumnByModule(List<Module> moduleList,
			String value, String fromDate, String toDate) throws ParseException {
		StringBuffer xml = new StringBuffer(
				"<chart showFCMenuItem='0' palette='2' caption=' ["
						+ fromDate
						+ "]  至  ["
						+ toDate
						+ "]   ' canvasBorderAlpha='20' bgColor='FFFFFF' canvasBorderThickness='1' showBorder='0' legendBorderAlpha='0' bgAngle='360' showlegend='1' showValues='1' decimals='2' useRoundEdges='0' baseFontSize ='9' outCnvbaseFontSize='10' use3DLighting='0' numberScaleValue='10000,1,1,1000' formatNumberScale='1' numberScaleUnit=' , ,万,千万 ' toolTipSepChar='：  ' plotFillRatio='100,0' chartRightMargin='6' chartTopMargin='0' chartLeftMargin='0' chartBottomMargin='3' showShadow='0' labelStep='2' animation='0'>");
		String f = fromDate;
		String t = toDate;
		Map<String, Module> tomap = new HashMap<String, Module>();
		for (Module module : moduleList) {
			String avgStopTime ="0.0";
				try {
					avgStopTime = StringUtil.proportion(String.valueOf(module.getStoptime()), module.getVisitCount().toString(), "0.1");
				} catch (UnsupportedEncodingException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			module.setModuleUserName(avgStopTime);
			tomap.put(Globals.FORMAT_TYPE_A.format(module.getReferDate()),
					module);
		}
		Map<String, String> map = new TreeMap<String, String>();
		map.put(f, "<set label='0' value='0' toolText='0'/>");
		while (!f.equals(t)) {
			f = Globals.FORMAT_TYPE_A.format(Globals.FORMAT_TYPE_A.parse(f)
					.getTime() + 1 * 24 * 3600 * 1000);
			map.put(f, "0");
		}
		map.put(t, "<set label='0' value='0' toolText='0'/>");
		for (Entry<String, String> entry : map.entrySet()) {
			String k = entry.getKey();
			Module maptovalue = tomap.get(k);
			if (null != maptovalue) {
				if (value.equals("pv")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getVisitCount() + "' toolText='来访次数: "
							+ maptovalue.getVisitCount() + "'/>");
				}
				if (value.equals("uv")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getUniqueHost() + "' toolText='独立访客: "
							+ maptovalue.getUniqueHost() + "'/>");
				}
				if (value.equals("ip")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getIp() + "' toolText='IP: "
							+ maptovalue.getIp() + "'/>");
				}
				if (value.equals("nuv")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getNewUniqueHost()
							+ "' toolText='新独立访客: "
							+ maptovalue.getNewUniqueHost() + "'/>");
				}
				if (value.equals("avgc")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getAvgCount() + "' toolText='人均浏览次数: "
							+ maptovalue.getAvgCount() + "'/>");
				}
				if (value.equals("avgtime")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getModuleUserName()
							+ "' toolText='平均停留时间: "
							+ maptovalue.getModuleUserName() + "'/>");
				}
			} else {

				if (value.equals("pv")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='来访次数: 0'/>");
				}
				if (value.equals("uv")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='独立访客: 0'/>");
				}
				if (value.equals("ip")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='IP: 0'/>");
				}
				if (value.equals("nuv")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='新独立访客: 0'/>");
				}
				if (value.equals("avgc")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='人均浏览次数: 0'/>");
				}
				if (value.equals("avgtime")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='平均停留时间: 0'/>");
				}
			}
		}
		xml.append("<styles><definition><style name='CaptionFont' type='font' size='12' /></definition><application><apply toObject='caption' styles='CaptionFont' /></application></styles></chart>");
		return xml.toString();

	}

	public static String getBrowserPie(List<Browser> browserList,
			String fromDate, String toDate) {
		StringBuffer xml = new StringBuffer(
				"<chart showFCMenuItem='0' toolTipSepChar=': ' numberScaleUnit=' , ,万,千万' formatNumberScale='1' numberScaleValue='10000,1,1,1000' palette='4' bgColor='666666' showPercentageValues='0' use3DLighting='1' chartsshowShadow='0' subcaption='"
						+ fromDate
						+ " - "
						+ toDate
						+ "' caption='访客浏览器分布-按浏览次数查询' showShadow='0' bgAlpha='0' baseFontSize='12' baseFontColor='000000' bgAngle='360' showBorder='0'  >");
		for (int i = 0; i < browserList.size(); i++) {
			xml.append("<set  value='" + browserList.get(i).getVisitCount()
					+ "' label='" + browserList.get(i).getBrowserName()
					+ "'  />");
		}
		xml.append("<styles><definition><style name='CaptionFont' type='font' bold='0' size='12'  /></definition><application><apply toObject='subcaption' styles='CaptionFont'  /></application></styles></chart>");
		return xml.toString();
	}

	public static String getBrowserMyLine(Map<String, Integer> browserMap) {
		StringBuffer xml = new StringBuffer(
				"<chart showFCMenuItem='0' baseFontSize='12' outCnvbaseFontSize='10' legendShadow='0' numberScaleUnit=' , ,万,千万' formatNumberScale='1' numberScaleValue='10000,1,1,1000' lineThickness='1' showValues='0' anchorRadius='1' divLineAlpha='20' divLineColor='CC3300' divLineIsDashed='1' showAlternateHGridColor='1' alternateHGridAlpha='5' alternateHGridColor='CC3300' shadowAlpha='40' labelStep='1' numvdivlines='1' chartsshowShadow='0' chartRightMargin='20' chartTopMargin='15' chartLeftMargin='0' chartBottomMargin='2' bgColor='FFFFFF' legendBorderAlpha='0' bgAngle='360' showlegend='1' borderColor='DEF3F3' canvasBorderThickness='1' lineColor='AFD8F8'><categories  >");
		for (int i = 29; i >= 0; i--) {
			if (i == 28 || i == 21 || i == 14 || i == 7 || i == 0)
				xml.append("<category label='"
						+ VelocityToolDateUtils.getDayFromAt(-i)
						+ "' showLabel='1'  />");
			else
				xml.append("<category label='"
						+ VelocityToolDateUtils.getDayFromAt(-i)
						+ "' showLabel='0'  />");
		}
		xml.append("</categories><dataset  seriesName='IE8'>");
		StringBuffer wangtongxml = new StringBuffer(
				"</dataset><dataset  seriesName='IE6' color='F6BD0F' anchorBorderColor='F6BD0F' anchorBgColor='F6BD0F'>");
		for (int x = 29; x >= 0; x--) {
			Integer dianxin = browserMap.get(VelocityToolDateUtils.getDay(-x)
					+ "IE8");
			Integer wangtong = browserMap.get(VelocityToolDateUtils.getDay(-x)
					+ "IE6");
			if (dianxin == null) {
				xml.append("<set  value='0' toolText='IE8: 0 PV "
						+ VelocityToolDateUtils.getDay(-x) + "'  />");
			}
			if (wangtong == null) {
				wangtongxml.append("<set  value='0' toolText='IE6: 0 PV "
						+ VelocityToolDateUtils.getDay(-x) + "'  />");
			}
			if (dianxin != null) {
				xml.append("<set  value='" + dianxin + "' toolText='IE8: "
						+ dianxin + " PV " + VelocityToolDateUtils.getDay(-x)
						+ "'  />");
			}
			if (wangtong != null) {
				wangtongxml.append("<set  value='" + wangtong
						+ "' toolText='IE6: " + wangtong + " PV "
						+ VelocityToolDateUtils.getDay(-x) + "'  />");
			}

		}
		xml.append(wangtongxml);
		xml.append("</dataset><styles><definition><style name='CaptionFont' type='font' size='12'  /><style name='myLegendFont' type='font' size='12'  /></definition><application><apply toObject='CAPTION' styles='CaptionFont'  /><apply toObject='SUBCAPTION' styles='CaptionFont'  /><apply toObject='Legend' styles='myLegendFont'  /></application></styles></chart>");
		return xml.toString();
	}

	public static String getBrowserStackedArea(Map<String, Integer> browserMap) {
		StringBuffer xml = new StringBuffer(
				"<chart showFCMenuItem='0' baseFontSize='12' outCnvbaseFontSize='10' numberScaleUnit=' , ,万,千万' formatNumberScale='1' numberScaleValue='10000,1,1,1000' bgColor='ffffff' bgborder='0' outCnvBaseFontColor='666666' showValues='0' numVDivLines='0' showAlternateVGridColor='0' showlegend='0' baseFontColor='000000' chartsshowShadow='0' canvasBorderThickness='0' borderColor='DEF3F3' showPlotBorder='0' plotFillAlpha='80' chartLeftMargin='0' chartRightMargin='20' areaBgColor='AFD8F8'><categories>");
		for (int i = 29; i >= 0; i--) {
			if (i == 28 || i == 21 || i == 14 || i == 7 || i == 0)
				xml.append("<category label='"
						+ VelocityToolDateUtils.getDayFromAt(-i)
						+ "' showLabel='1'  />");
			else
				xml.append("<category label='"
						+ VelocityToolDateUtils.getDayFromAt(-i)
						+ "' showLabel='0'  />");
		}
		xml.append("</categories><dataset  seriesName='总浏览次数' color='49acff' plotBorderColor='0067be'>");
		for (int x = 29; x >= 0; x--) {
			Integer pvcount = browserMap.get(VelocityToolDateUtils.getDay(-x));
			if (pvcount == null) {
				xml.append("<set value='0' toolText='总访问量: 0 PV "
						+ VelocityToolDateUtils.getDay(-x) + "'/>");
			}

			if (pvcount != null) {
				xml.append("<set value='" + pvcount + "' toolText='总访问量: "
						+ pvcount + " PV " + VelocityToolDateUtils.getDay(-x)
						+ "'/>");
			}
		}
		xml.append("</dataset><styles><definition><style name='TrendAnim' type='animation' param='_alpha' duration='1' start='1'  /></definition><application><apply toObject='TRENDLINES' styles='TrendAnim'  /></application></styles></chart>");
		return xml.toString();
	}

	public static String getColumnByBrowser(List<Browser> browserList,
			String value, String fromDate, String toDate) throws ParseException {
		StringBuffer xml = new StringBuffer(
				"<chart showFCMenuItem='0' palette='2' caption=' ["
						+ fromDate
						+ "]  至  ["
						+ toDate
						+ "]   ' canvasBorderAlpha='20' bgColor='FFFFFF' canvasBorderThickness='1' showBorder='0' legendBorderAlpha='0' bgAngle='360' showlegend='1' showValues='1' decimals='2' useRoundEdges='0' baseFontSize ='9' outCnvbaseFontSize='10' use3DLighting='0' numberScaleValue='10000,1,1,1000' formatNumberScale='1' numberScaleUnit=' , ,万,千万 ' toolTipSepChar='：  ' plotFillRatio='100,0' chartRightMargin='6' chartTopMargin='0' chartLeftMargin='0' chartBottomMargin='3' showShadow='0' labelStep='2' animation='0'>");
		String f = fromDate;
		String t = toDate;
		Map<String, Browser> tomap = new HashMap<String, Browser>();
		for (Browser browser : browserList) {
			tomap.put(Globals.FORMAT_TYPE_A.format(browser.getReferDate()),
					browser);
		}
		Map<String, String> map = new TreeMap<String, String>();
		map.put(f, "<set label='0' value='0' toolText='0'/>");
		while (!f.equals(t)) {
			f = Globals.FORMAT_TYPE_A.format(Globals.FORMAT_TYPE_A.parse(f)
					.getTime() + 1 * 24 * 3600 * 1000);
			map.put(f, "0");
		}
		map.put(t, "<set label='0' value='0' toolText='0'/>");
		for (Entry<String, String> entry : map.entrySet()) {
			String k = entry.getKey();
			Browser maptovalue = tomap.get(k);
			if (null != maptovalue) {
				if (value.equals("pv")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getVisitCount() + "' toolText='来访次数: "
							+ maptovalue.getVisitCount() + "'/>");
				}
				if (value.equals("uv")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getUniqueHost() + "' toolText='独立访客: "
							+ maptovalue.getUniqueHost() + "'/>");
				}
				if (value.equals("ip")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getIp() + "' toolText='IP: "
							+ maptovalue.getIp() + "'/>");
				}
				if (value.equals("nuv")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getNewUniqueHost()
							+ "' toolText='新独立访客: "
							+ maptovalue.getNewUniqueHost() + "'/>");
				}
				if (value.equals("avgc")) {
					xml.append("<set label='" + k + "' value='"
							+ maptovalue.getAvgCount() + "' toolText='人均浏览次数: "
							+ maptovalue.getAvgCount() + "'/>");
				}
				if (value.equals("avgtime")) {
					Double avgTime = 0D;
					try {
						String avgTimes = StringUtil.proportion(
								String.valueOf(maptovalue.getAvgStopTime()),
								maptovalue.getVisitCount().toString(), "0.1");
						avgTime = Double.valueOf(avgTimes);
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					xml.append("<set label='" + k + "' value='" + avgTime
							+ "' toolText='平均停留时间: " + avgTime + "'/>");
				}
			} else {

				if (value.equals("pv")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='来访次数: 0'/>");
				}
				if (value.equals("uv")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='独立访客: 0'/>");
				}
				if (value.equals("ip")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='IP: 0'/>");
				}
				if (value.equals("nuv")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='新独立访客: 0'/>");
				}
				if (value.equals("avgc")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='人均浏览次数: 0'/>");
				}
				if (value.equals("avgtime")) {
					xml.append("<set label='" + k
							+ "' value='0' toolText='平均停留时间: 0'/>");
				}
			}
		}
		xml.append("<styles><definition><style name='CaptionFont' type='font' size='12' /></definition><application><apply toObject='caption' styles='CaptionFont' /></application></styles></chart>");
		return xml.toString();
	}
}